// OpenGL Render Context
// (c) jimon game studio

#ifndef JEH_CRENDERCONTEXT_OPENGL
#define JEH_CRENDERCONTEXT_OPENGL

#include "IRenderContext.h"
#include "CRender_OpenGL_Extensions.h"
#include "jeOpenGLSystemHeader.h"

#ifdef JE_RENDER_OPENGL

#include "jeOpenGLWorkMode.h"

#ifdef JE_DEVICE_LINUX
#include <GL/glx.h>
#include <X11/X.h>
#endif

namespace je
{
	namespace video
	{
		//! OpenGL Render Context
		class CRenderContext_OpenGL:public je::video::IRenderContext
		{
		private:
			//! Extensions
			CRender_OpenGL_Extensions * Extensions;

			//! Render Window
			device::IWindow * RenderWindow;

			#ifdef JE_DEVICE_WIN
				//! Render Window Device Context
				HDC DeviceContext;

				//! OpenGL Render Context
				HGLRC RenderContext;
			#endif

			#ifdef JE_DEVICE_LINUX
				//! GLX context
				GLXContext CurrentGLXContext;
			#endif

			//! Viewport Size
			jeVector2di ViewportSize;

			//! Use window in full size
			u1 FullWindowUse;

			//! Use VSync
			u1 VSyncFlag;

			//! Create OpenGL Context
			void CreateOpenGLContext();

			//! Delete OpenGL Context
			void DeleteOpenGLContext();

			//! Get Optimal Pixel Format
			s32 GetOptimalPixelFormat(s32 Depth,s32 Samples);

			//! OpenGL Work Mode
			OpenGLWorkMode CurrentWorkMode;

			//! Need To Update Extensions
			u1 NeedToUpdateExtensions;
		public:
			//! Constructor
			CRenderContext_OpenGL(CRender_OpenGL_Extensions * extensions,OpenGLWorkMode WorkMode);

			//! Destructor
			~CRenderContext_OpenGL();

			//! Init Use Of Context
			void InitContext();

			//! DeInit Use Of Context
			void DeInitContext();

			//! Set Window for render
			void SetWindow(device::IWindow * Window);

			//! Get current render window
			device::IWindow * GetWindow();

			//! Set Viewport Size
			void SetSize(const jeVector2di & Size);

			//! Get Viewport Size
			const jeVector2di & GetSize();

			//! If true, render context use full window client space
			void SetFullWindowUse(u1 Use);

			//! return fullwindowuse flag
			u1 IsFullWindowUse();

			//! Set VSync Flag
			void SetVSyncFlag(u1 Flag);

			//! Return VSync Flag
			u1 GetVSyncFlag();

			//! Get Api Pointer
			void * GetApiPointer(RenderContextApiPointerType Type);
		};
	}
}

#endif
#endif
